package com.shujia.mr.sort;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Score implements WritableComparable<Score> {
    String studentID;
    String totalScore;

    public Score() {
    }

    public Score(String studentID, String totalScore) {
        this.studentID = studentID;
        this.totalScore = totalScore;
    }


    @Override
    public String toString() {
        return "Score{" +
                "studentID='" + studentID + '\'' +
                ", totalScore='" + totalScore + '\'' +
                '}';
    }

    public String getStudentID() {
        return studentID;
    }

    public void setStudentID(String studentID) {
        this.studentID = studentID;
    }

    public String getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(String totalScore) {
        this.totalScore = totalScore;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(studentID);
        out.writeUTF(totalScore);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        studentID = in.readUTF();
        totalScore = in.readUTF();
    }

    @Override
    public int compareTo(Score other) {
        int thisValue = Integer.parseInt(this.totalScore);
        int thatValue = Integer.parseInt(other.totalScore);
        return -(thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1));
    }
}
